home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 June
/
EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso
/
earcd
/
cmdity
/
yk212src.lha
/
Yak_2.12_Src
/
WBStartup
/
DigitalClock.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-02-07
|
24KB
|
989 lines
/*
** Module: DigitalClock (DC)
**
** Purpose: displays up a digital clock in the top right corner
** of title bar screen
**
** Largely inspired from Anders Hammarquist TitleClock source
**
*/
#define DEBUG
#include <dos/datetime.h>
#include <dos/dos.h>
#include <exec/memory.h>
#include <exec/execbase.h>
#include <exec/devices.h>
#include <exec/libraries.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <graphics/gfx.h>
#include <libraries/commodities.h>
#include <libraries/iffparse.h>
#include <libraries/locale.h>
#include <devices/timer.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/icon.h>
#include <proto/iffparse.h>
#include <proto/utility.h>
#include <proto/commodities.h>
#include <proto/timer.h>
#include <proto/locale.h>
#include <workbench/workbench.h>
#include <workbench/startup.h>
#include <string.h>
#include "yak.h"
#include "code.h"
#include "DigitalClock.h"
#include "GetScreenBox.h"
#include "settings.h"
#include "Hotkey_types.h"
#ifdef STAND_ALONE
struct Locale *locale;
#else
# define CATCOMP_BLOCK
# define CATCOMP_NUMBERS
# include "yak_locale_strings.h"
#endif
/* Maximum length of text displayed in clock */
#define DC_C0_MAXCLOCKLEN 50
/* From sysiclass docs */
#define DC_C0_LOWDEPTHWIDTH 17
#define DC_C0_HIDEPTHWIDTH 23
static struct RastPort *DC_V0_RPort = NULL;
static struct BitMap *DC_V0_BitMap = NULL;
static struct TextFont *DC_V0_TitleFont;
static struct TextFont *DC_V0_Old_TitleFont;
static struct Screen *DC_V0_Old_Scr;
static int DC_V0_BltLen;
static int DC_V0_Old_BltLen;
static int DC_V0_LeftEdge;
static int DC_V0_Old_LeftEdge;
static UWORD DC_V0_FrontPen;
static UWORD DC_V0_BackPen;
static UWORD DC_V0_Old_BackPen;
static struct timerequest *DC_V0_TimerIO = NULL;
static struct MsgPort *DC_V0_TimerPort = NULL;
ULONG DC_V_TimerSig;
struct Library *TimerBase;
/* Default configuration of the clock */
const DC_T_Config DC_C0_Config_Def =
{
DC_C_UNACTIVE,
5,
1,
FALSE,
FALSE,
FALSE,
FALSE,
DC_C_FormatDos,
NULL,
DC_C_FrontPubScreen,
{"#?", NULL},
FALSE
};
/* Current configuration of the clock */
DC_T_Config DC_V_Config;
/* Indicates whether or not the clock has been initialized */
BOOL DC_V0_Initialized = FALSE;
#if !defined(PREFS) && !defined(CONV)
/* Function prototypes */
static void DC_F0_DisplayOnSelectedScreen (char *, unsigned int );
static void DC_F0_DisplayClk(char *, unsigned int, struct Screen * );
static void DC_F0_DeleteClk(void);
static void DC_F0_UpdateClk(void);
static void
DC_F0_AbortTimer(void)
{
if (DC_V_Config.TimerRunning == TRUE)
{
/* Abort timer request */
AbortIO(&DC_V0_TimerIO->tr_node);
WaitIO(&DC_V0_TimerIO->tr_node);
DC_V_Config.TimerRunning = FALSE;
}
}
void
DC_F_CleanUp(void)
{
DC_F0_AbortTimer();
DC_F0_DeleteClk();
if (DC_V0_BitMap)
{
FreeVec(DC_V0_BitMap->Planes[0]);
FreeVec(DC_V0_BitMap);
}
FreeVec(DC_V0_RPort);
FreeVec(DC_V_Config.LocaleDateFormat);
FreeVec(DC_V_Config.ScreenPatternData.pat);
/* Timer stuff */
if (DC_V0_TimerIO)
{
CloseDevice(DC_V0_TimerIO);
DeleteIORequest(&DC_V0_TimerIO->tr_node);
}
if (DC_V0_TimerPort)
DeleteMsgPort(DC_V0_TimerPort);
TimerBase = (struct Library *)(-1);
}
void
DC_F_DisableClock(void)
{
DC_F0_AbortTimer();
DC_F0_DeleteClk();
}
void
DC_F_EnableClock(void)
{
DC_F0_AbortTimer();
DC_F0_UpdateClk();
}
/*
* Init DigitalClock module
*/
int
DC_F_Init(void)
{
if (DC_V0_Initialized == FALSE)
{
if (!(DC_V0_TimerPort = CreateMsgPort()))
{
return 1;
}
if (DC_V_TimerSig == 0)
{
DC_V_TimerSig = 1 << DC_V0_TimerPort->mp_SigBit;
}
if (!(DC_V0_TimerIO = (struct timerequest *)
CreateIORequest(DC_V0_TimerPort, sizeof(struct timerequest))))
{
return 1;
}
/* Open timer.device */
if (OpenDevice(TIMERNAME, UNIT_WAITUNTIL, &DC_V0_TimerIO->tr_node, 0))
{
return 1;
}
/* Library pointer */
TimerBase = (struct Library *)DC_V0_TimerIO->tr_node.io_Device;
/* Init timerequest */
DC_V0_TimerIO->tr_node.io_Command = TR_ADDREQUEST;
DC_V0_TimerIO->tr_time.tv_micro = 0;
/* Initialize Screen Pattern */
if (DC_V_Config.ScreenSelection == DC_C_ScreensByPattern)
{
InitPattern(NULL, &DC_V_Config.ScreenPatternData);
}
/* Allocate BitMap and RastPort */
DC_V0_BitMap = AllocVec(sizeof(struct BitMap), MEMF_CLEAR|MEMF_PUBLIC);
DC_V0_RPort = AllocVec(sizeof(struct RastPort),MEMF_CLEAR|MEMF_PUBLIC);
if (DC_V0_BitMap && DC_V0_RPort)
{
InitRastPort(DC_V0_RPort);
DC_V0_RPort->BitMap = DC_V0_BitMap;
}
else
{
DC_V0_Initialized = FALSE;
return 1;
}
DC_V0_Initialized = TRUE;
}
if (DC_V_Config.State == DC_C_ACTIVE)
{
RegisterSignal(DC_V_TimerSig);
DC_F_EnableClock();
}
else
{
DC_F_DisableClock();
}
return 0;
}
void
DC_F_ProcessMsg(
long sig)
{
if (sig & DC_V_TimerSig)
{
while (GetMsg(DC_V0_TimerPort))
{
if (DC_V_Config.TimerRunning == TRUE)
DC_F0_UpdateClk();
}
}
}
void ASM
SPFunc(
REG(a0) struct Hook *pHook,
REG(a1) char pChar)
{
/* Quick-and-dirty isprint() +
* make sure that we're not
* printing too many chars.
*/
if ((pChar&0x60) &&
((int)pHook->h_Data - (int)pHook->h_SubEntry < DC_C0_MAXCLOCKLEN))
*((*(char **)&(pHook->h_Data))++) = pChar;
}
/* Print hook */
struct Hook DC_V0_PrintHook =
{
NULL, NULL, /* MinNode */
(ULONG (* )())SPFunc, /* h_Entry, PrintFunc */
NULL, /* h_SubEntry. Dirtily used as pointer for */
/* where the string began. */
NULL /* h_Data, where to put char */
};
/* print date */
int
SPrintD(
char *I_Dest,
char *I_Fmt,
struct DateStamp *I_Date)
{
DC_V0_PrintHook.h_SubEntry = (ULONG (* )())(DC_V0_PrintHook.h_Data = I_Dest);
FormatDate(locale, I_Fmt, I_Date, &DC_V0_PrintHook);
*((char *)DC_V0_PrintHook.h_Data) = '\0';
return ((int)((char *)DC_V0_PrintHook.h_Data - I_Dest)); /* return length of string */
}
/* Delete previous clock */
static void
DC_F0_DeleteClk(void)
{
if (DC_V0_Old_Scr && DC_V0_Old_Scr->BarLayer &&
AttemptLockLayerRom(DC_V0_Old_Scr->BarLayer))
{
/* Empty RastPort */
SetRast(DC_V0_RPort, DC_V0_Old_BackPen);
ClipBlit(DC_V0_RPort, 0, 0, DC_V0_Old_Scr->BarLayer->rp, DC_V0_Old_LeftEdge, 1, DC_V0_Old_BltLen, DC_V0_Old_TitleFont->tf_YSize, 0x0C0);
UnlockLayerRom(DC_V0_Old_Scr->BarLayer);
}
}
/* Display clock on appropriate screen */
static void
DC_F0_DisplayClk(
char *clkstr,
unsigned int clklen,
struct Screen *Scr)
{
struct IBox box;
if (Scr->BarLayer && AttemptLockLayerRom(Scr->BarLayer))
{
struct DrawInfo *dri;
int i;
WORD dSize;
DC_V0_TitleFont = Scr->BarLayer->rp->Font; /* No need to 'open' it */
if ((DC_V0_BitMap->Depth < MIN(Scr->RastPort.BitMap->Depth, 8)) ||
(DC_V0_BitMap->Rows < DC_V0_TitleFont->tf_YSize) ||
(DC_V0_BitMap->BytesPerRow < Scr->RastPort.BitMap->BytesPerRow))
{
/* Need 'better' rastport */
FreeVec(DC_V0_BitMap->Planes[0]);
InitBitMap(DC_V0_BitMap,
MAX(DC_V0_BitMap->Depth, MIN(Scr->RastPort.BitMap->Depth,8)),
Scr->Width,
MAX(DC_V0_BitMap->Rows, DC_V0_TitleFont->tf_YSize));
if (!(DC_V0_BitMap->Planes[0] = AllocVec(DC_V0_BitMap->BytesPerRow*DC_V0_BitMap->Rows*DC_V0_BitMap->Depth, MEMF_CHIP)))
{
DC_V0_BitMap->Depth = 0;
goto next;
}
for (i = 1; i < MIN(DC_V0_BitMap->Depth,8); i++)
{
DC_V0_BitMap->Planes[i] = ((UBYTE *)DC_V0_BitMap->Planes[i-1])
+ DC_V0_BitMap->BytesPerRow*DC_V0_BitMap->Rows;
}
}
if (dri = GetScreenDrawInfo(Scr))
{
if (dri->dri_NumPens >= 0x000A)
{
DC_V0_FrontPen = dri->dri_Pens[BARDETAILPEN];
DC_V0_BackPen = dri->dri_Pens[BARBLOCKPEN];
}
else
{
DC_V0_FrontPen = dri->dri_Pens[DETAILPEN];
DC_V0_BackPen = dri->dri_Pens[BLOCKPEN];
}
FreeScreenDrawInfo(Scr,dri);
}
/* If we don't get DrawInfo, the pens will be somewhat random */
SetFont(DC_V0_RPort, DC_V0_TitleFont);
SetDrMd(DC_V0_RPort, JAM2);
SetAPen(DC_V0_RPort, DC_V0_FrontPen);
SetBPen(DC_V0_RPort, DC_V0_BackPen);
SetRast(DC_V0_RPort, DC_V0_BackPen);
Move(DC_V0_RPort, DC_V0_TitleFont->tf_XSize, DC_V0_TitleFont->tf_Baseline);
Text(DC_V0_RPort, clkstr, clklen);
dSize = (Scr->Flags & SCREENHIRES?DC_C0_HIDEPTHWIDTH:DC_C0_LOWDEPTHWIDTH);
DC_V0_BltLen = DC_V0_RPort->cp_x + DC_V_Config.Offset;
GetScreenBox(Scr, &box, FALSE);
DC_V0_LeftEdge = MIN(Scr->Width - dSize, box.Left + box.Width);
DC_V0_LeftEdge -= DC_V0_BltLen;
/* If we have change screen since last update, remove clock from old screen
* as it won't be updated anymore.
* Same thing, if our clock has moved due to auto-scroll screens.
*/
if ((Scr != DC_V0_Old_Scr) ||
(DC_V0_Old_LeftEdge != DC_V0_LeftEdge))
{
DC_F0_DeleteClk();
}
ClipBlit(DC_V0_RPort, 0, 0, Scr->BarLayer->rp, DC_V0_LeftEdge, 1, DC_V0_BltLen, DC_V0_TitleFont->tf_YSize, 0x0C0);
next:
UnlockLayerRom(Scr->BarLayer);
}
}
static void
DC_F0_DisplayOnSelectedScreen (
char *DispStr,
unsigned int StringLen)
{
ULONG ILock;
struct Screen *Scr;
/* This is part while the IntuitionBase lock is held not-quite
* legal. The AutoDoc says not to call any intuition,
* graphics, etc functions while holding the lock, but it
* seems to work. My guess is that the warning in the AutoDoc
* is to keep people from locking up the machine trying to
* draw while someone has a layer locked. If this is the
* reason, then the following should not cause any problems
* what so ever, since I won't draw unless I get to lock the
* layer. If there is some other obscure reason, then this may
* cause problems on some systems. But so far I haven't seen
* or heard of any problems with it, and it's really the only
* way to do what we want to do.
*/
ILock = LockIBase(0);
switch (DC_V_Config.ScreenSelection)
{
case DC_C_WorkbenchScreen:
if (Scr = LockPubScreen("Workbench"))
{
DC_F0_DisplayClk(DispStr, StringLen, Scr);
UnlockPubScreen(NULL,Scr);
}
break;
case DC_C_FrontScreen:
Scr = IntuitionBase->FirstScreen;
if (Scr != NULL)
{
DC_F0_DisplayClk(DispStr, StringLen, Scr);
}
break;
case DC_C_FrontPubScreen:
Scr = IntuitionBase->FirstScreen;
if ((Scr != NULL) &&
((Scr->Flags & SCREENTYPE) != CUSTOMSCREEN))
{
DC_F0_DisplayClk(DispStr, StringLen, Scr);
}
else
{
/* If new screen doesn't apply, update old one */
if ((DC_V0_Old_Scr != NULL) &&
((DC_V0_Old_Scr->Flags & SCREENTYPE) != CUSTOMSCREEN))
{
Scr = DC_V0_Old_Scr;
DC_F0_DisplayClk(DispStr, StringLen, Scr);
}
else
{
Scr = NULL;
}
}
break;
case DC_C_DefPubScreen:
if (Scr = LockPubScreen(NULL))
{
DC_F0_DisplayClk(DispStr, StringLen, Scr);
UnlockPubScreen(NULL, Scr);
}
break;
case DC_C_ScreensByPattern:
Scr = IntuitionBase->FirstScreen;
if ((Scr != NULL) &&
DC_V_Config.ScreenPatternData.patstr &&
Scr->DefaultTitle &&
MatchPattern(DC_V_Config.ScreenPatternData.pat, Scr->DefaultTitle))
{
DC_F0_DisplayClk(DispStr, StringLen, Scr);
}
else
{
/* If new screen doesn't apply, update old one */
if ((DC_V0_Old_Scr != NULL) &&
DC_V_Config.ScreenPatternData.patstr &&
DC_V0_Old_Scr->DefaultTitle &&
MatchPattern(DC_V_Config.ScreenPatternData.pat, DC_V0_Old_Scr->DefaultTitle))
{
Scr = DC_V0_Old_Scr;
DC_F0_DisplayClk(DispStr, StringLen, Scr);
}
else
{
Scr = NULL;
}
}
break;
}
UnlockIBase(ILock);
if (Scr != NULL)
{
DC_V0_Old_Scr = Scr;
}
}
/* Update clock */
static void
DC_F0_UpdateClk(void)
{
struct DateTime dt;
char DispStr[DC_C0_MAXCLOCKLEN];
unsigned int V_StringLen;
/* Save parameters of last display */
DC_V0_Old_LeftEdge = DC_V0_LeftEdge;
DC_V0_Old_BltLen = DC_V0_BltLen;
DC_V0_Old_BackPen = DC_V0_BackPen;
DC_V0_Old_TitleFont = DC_V0_TitleFont;
DispStr[0] = '\0';
DateStamp(&dt.dat_Stamp);
if ((DC_V_Config.DateFormat != DC_C_LocaleDateFormat) ||
(LocaleBase == NULL))
{
char StrDay[20];
char StrDate[20];
char StrTime[20];
int len;
dt.dat_Format = (UBYTE)DC_V_Config.DateFormat;
dt.dat_Flags = 0;
if (DC_V_Config.ShowDay == TRUE)
{
dt.dat_StrDay = StrDay;
}
else
{
dt.dat_StrDay = NULL;
}
if (DC_V_Config.ShowDate == TRUE)
{
dt.dat_StrDate = StrDate;
}
else
{
dt.dat_StrDate = NULL;
}
dt.dat_StrTime = StrTime;
DateToStr(&dt);
if (DC_V_Config.ShowDay == TRUE)
{
if (DC_V_Config.ShortDay == TRUE)
{
StrDay[3] = ' ';
StrDay[4] = '\0';
}
else
{
len = strlen(StrDay);
StrDay[len] = ' ';
StrDay[len + 1] = '\0';
}
strcat(DispStr, StrDay);
}
if (DC_V_Config.ShowDate == TRUE)
{
len = strlen(StrDate);
StrDate[len] = ' ';
StrDate[len + 1] = '\0';
strcat(DispStr, StrDate);
}
if (DC_V_Config.ShowSecs == FALSE)
{
len = strlen(StrTime);
StrTime[len - 3] = '\0';
}
strcat(DispStr, StrTime);
V_StringLen = strlen(DispStr);
}
else
{
/* Use Locale Format Date */
V_StringLen = SPrintD(DispStr, DC_V_Config.LocaleDateFormat, &dt.dat_Stamp);
}
/* Now display the things on the right screen */
DC_F0_DisplayOnSelectedScreen(DispStr, V_StringLen);
/* reschedule timer */
GetSysTime(&DC_V0_TimerIO->tr_time);
DC_V0_TimerIO->tr_time.tv_secs += DC_V_Config.Interval;
DC_V0_TimerIO->tr_time.tv_micro = 0;
SendIO(&DC_V0_TimerIO->tr_node);
DC_V_Config.TimerRunning = TRUE;
}
#endif /* not CONV and not PREFS */
void
DC_F_Set_Default(void)
{
memmove((void *)&DC_V_Config, (void const *)&DC_C0_Config_Def, sizeof(DC_T_Config));
}
#ifndef CONV
/* YKDC chunk format
*
* UWORD NUM_HANDLERS
* UWORD DC_V_Config.State
* UWORD DC_V_Config.Offset
* LONG DC_V_Config.Interval
* BOOL DC_V_Config.ShowDate
* BOOL DC_V_Config.ShowDay
* BOOL DC_V_Config.ShortDay
* BOOL DC_V_Config.ShowSecs
* UWORD DC_V_Config.DateFormat
* STRING DC_V_Config.LocaleDateFormat
* UWORD DC_V_Config.ScreenSelection
* STRING DC_V_Config.ScreenPatternStr
*
*/
APTR
ReadDigitalClock(UBYTE *chunkbuf, ULONG size)
{
register UWORD *puword=(UWORD *)chunkbuf;
register LONG *plong;
register UBYTE *pstr;
char *str;
DC_V_Config.State = *puword++;
DC_V_Config.Offset = *puword++;
plong = (LONG *)puword;
DC_V_Config.Interval = *plong++;
puword = (UWORD *)plong;
DC_V_Config.ShowDate = (BOOL) *puword++;
DC_V_Config.ShowDay = (BOOL) *puword++;
DC_V_Config.ShortDay = (BOOL) *puword++;
DC_V_Config.ShowSecs = (BOOL) *puword++;
DC_V_Config.DateFormat = (BOOL) *puword++;
pstr = (UBYTE *)puword;
str = DupStr(pstr);
if (DC_V_Config.LocaleDateFormat)
{
FreeVec(DC_V_Config.LocaleDateFormat);
}
DC_V_Config.LocaleDateFormat = str;
pstr += strlen(str)+1;
puword = (UWORD *)WORD_ALIGN(pstr);
DC_V_Config.ScreenSelection = *puword++;
pstr = (UBYTE *)puword;
strncpy(DC_V_Config.ScreenPatternData.patstr, pstr, PATLEN);
DC_V_Config.ScreenPatternData.patstr[PATLEN] = '\0';
pstr += strlen(pstr)+1;
#ifndef PREFS
if (DC_F_Init() != 0)
return "Init of clock failed";
#endif
if ((pstr-chunkbuf) == size)
return 0L; /* Reading Ok */
return Reading_chunk_ERR;
}
#endif /* not CONV */
#if defined(PREFS) || defined(CONV)
APTR
WriteDigitalClock(struct IFFHandle *iff, UBYTE *chunkbuf)
{
register UWORD *puword=(UWORD *)chunkbuf;
register LONG *plong;
register UBYTE *pstr;
ULONG size;
*puword++ = DC_V_Config.State;
*puword++ = DC_V_Config.Offset;
plong = (LONG *)puword;
*plong++ = DC_V_Config.Interval;
puword = (UWORD *)plong;
*puword++ = DC_V_Config.ShowDate;
*puword++ = DC_V_Config.ShowDay;
*puword++ = DC_V_Config.ShortDay;
*puword++ = DC_V_Config.ShowSecs;
*puword++ = DC_V_Config.DateFormat;
pstr = (UBYTE *)puword;
strcpy(pstr, DC_V_Config.LocaleDateFormat);
pstr += strlen(pstr)+1;
/* Take care of non word aligned addresses for 68000 */
puword = (UWORD *)WORD_ALIGN(pstr);
*puword++ = DC_V_Config.ScreenSelection;
pstr = (UBYTE *)puword;
strcpy(pstr, DC_V_Config.ScreenPatternData.patstr);
pstr += strlen(pstr)+1;
/* Write Chunk */
size = pstr - chunkbuf;
if ((PushChunk(iff, 0, ID_YKDC, size)) ||
(WriteChunkBytes(iff, chunkbuf, size) != size) ||
(PopChunk(iff)))
return Writing_prefs_file_ERR;
/* All OK. */
return 0L;
}
#endif /* PREFS || CONV */
#ifdef STAND_ALONE
/**************************************************************************/
/**************************************************************************/
/* Below are some functions to test DigitalClock as a stand alone program */
/**************************************************************************/
/**************************************************************************/
#include <graphics/videocontrol.h>
struct MsgPort *broker_mp;
CxObj *broker;
static struct NewBroker newbroker =
{
NB_VERSION,
"DigitalClock",
"DigitalClock",
"Displays clock in screen titlebar",
NBU_UNIQUE|NBU_NOTIFY,
0,
0,
0,
0
};
int
main(void)
{
int CXSig;
long sig;
CxMsg *CXMsg;
/* Open needed libraries */
DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",37);
GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37);
IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37);
UtilityBase = OpenLibrary("utility.library",37);
CxBase = OpenLibrary("commodities.library",37);
LocaleBase = OpenLibrary("locale.library",38);
if (!(DOSBase && GfxBase && IntuitionBase && UtilityBase && CxBase))
/* didn't open */
goto cleanup;
if (LocaleBase)
locale = OpenLocale(NULL);
newbroker.nb_Pri = 0;
if (!(broker_mp = CreateMsgPort()))
goto cleanup;
CXSig = 1L << broker_mp->mp_SigBit;
newbroker.nb_Port = broker_mp;
if (!(broker = CxBroker(&newbroker,NULL)))
goto cleanup;
ActivateCxObj(broker,1L);
if (DC_F_Init())
goto cleanup;
/* Setup done */
{
BOOL Abort = FALSE;
DC_F_EnableClock();
while(!Abort)
{
sig = Wait(CXSig|DC_V_TimerSig|SIGBREAKF_CTRL_C);
DC_F_ProcessMsg(sig);
while(CXMsg = (CxMsg *)GetMsg(broker_mp))
{
const int msgid = CxMsgID(CXMsg);
const int msgtype = CxMsgType(CXMsg);
ReplyMsg((struct Message *)CXMsg);
if (msgtype == CXM_COMMAND)
switch(msgid)
{
case CXCMD_DISABLE:
DC_F_DisableClock();
ActivateCxObj(broker, 0);
break;
case CXCMD_ENABLE:
DC_F_EnableClock();
ActivateCxObj(broker, 1);
break;
case CXCMD_KILL:
case CXCMD_UNIQUE:
Abort = TRUE;
}
}
if (sig & SIGBREAKF_CTRL_C)
{
Abort = TRUE;
}
}
}
cleanup:
DC_F_CleanUp();
/* Commodity stuff */
if (broker)
{
DeleteCxObj(broker);
while(CXMsg = (CxMsg *)GetMsg(broker_mp))
ReplyMsg((struct Message *)CXMsg);
}
if (broker_mp) DeleteMsgPort(broker_mp);
CloseLocale(locale);
CloseLibrary(LocaleBase);
CloseLibrary(IconBase);
CloseLibrary(UtilityBase);
CloseLibrary(CxBase);
CloseLibrary((struct Library *)IntuitionBase);
CloseLibrary((struct Library *)GfxBase);
CloseLibrary((struct Library *)DOSBase);
return 0;
}
void __regargs
GetScreenBox(struct Screen *s,
struct IBox *box,
UWORD bar)
{
struct ViewPortExtra *vpe;
struct TagItem vpe_tags[2];
vpe_tags[0].ti_Data = NULL;
vpe_tags[0].ti_Tag = VTAG_VIEWPORTEXTRA_GET;
vpe_tags[1].ti_Tag = TAG_DONE;
VideoControl(s->ViewPort.ColorMap, vpe_tags);
if (vpe = (struct ViewPortExtra *)vpe_tags[0].ti_Data)
{
/*
* Size of the visible part of the screen
* Is there an easier way to do it ?
*/
box->Left = vpe->DisplayClip.MinX;
box->Top = vpe->DisplayClip.MinY;
box->Width = vpe->DisplayClip.MaxX - box->Left + 1;
box->Height = vpe->DisplayClip.MaxY - box->Top + 1;
if (s->LeftEdge < 0)
box->Left = -s->LeftEdge;
else
box->Left = 0;
if (s->TopEdge < 0)
box->Top = -s->TopEdge;
else
box->Top = 0;
}
else
{
box->Left = 0;
box->Top = 0;
box->Width = s->Width;
box->Height = s->Height;
}
if (bar)
{
if (box->Top <= s->BarHeight)
{
int l = s->BarHeight + 1;
box->Height -= (l - box->Top);
box->Top = l;
}
}
}
/* parse pattern, report errors */
__regargs BOOL
InitPattern(char *newpatstr, PatternData *pdata)
{
char *patstr = newpatstr ? newpatstr : pdata->patstr;
char *pat;
LONG len;
if (pat = AllocVec(len = strlen(patstr)*3+10, MEMF_CLEAR))
{
if (ParsePattern(patstr, pat, len) != -1)
{
if (newpatstr) strncpy(pdata->patstr, newpatstr, PATLEN);
if (pdata->pat) FreeVec(pdata->pat);
pdata->pat = pat;
return TRUE;
}
FreeVec(pat);
}
return FALSE;
}
#endif